//
//  CAAnimationDelegateToBlock.swift
//  NetEaseMusic
//
//  Created by SAGESSE on 2020/2/14.
//  Copyright © 2020 SAGESSE. All rights reserved.
//

import UIKit

class CAAnimationDelegateToBlock: NSObject, CAAnimationDelegate {
    
    var didStart: ((CAAnimation) -> Void)?
    var didStop: ((CAAnimation, Bool) -> Void)?
    
    func animationDidStart(_ anim: CAAnimation) {
        didStart?(anim)
    }
    
    func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
        didStop?(anim, flag)
    }
    
    static func didStart(_ didStart: @escaping ((CAAnimation) -> Void)) -> CAAnimationDelegateToBlock {
        let newValue = CAAnimationDelegateToBlock()
        newValue.didStart = didStart
        return newValue
    }
    
    static func didStop(_ didStop: @escaping ((CAAnimation, Bool) -> Void)) -> CAAnimationDelegateToBlock {
        let newValue = CAAnimationDelegateToBlock()
        newValue.didStop = didStop
        return newValue
    }
}
